package pers.vic.blog.module.api.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import pers.vic.blog.module.api.service.BlogCategoryService;
import pers.vic.boot.base.controller.BaseController;

import pers.vic.blog.module.api.model.BlogCategory;
import pers.vic.boot.base.model.BaseResponse;
import pers.vic.boot.base.vo.Select2VO;
import pers.vic.boot.util.CommonUtils;

import java.util.List;

/**
 * @description:博客分类表 控制层
 * @author Vic.xu
 * @date: 2020-05-08 09:38
 */
@RestController
@RequestMapping("/blog/category")
public class BlogCategoryController extends BaseController<BlogCategoryService, BlogCategory>{

    /**
     * 全部分类
     */
    @RequestMapping( value = "all")
    public BaseResponse<?> all(){
        BlogCategory lookup = new BlogCategory();
        lookup.setEnable(true);
        List<BlogCategory> list = service.list(lookup);
        List<Select2VO> result = CommonUtils.listFilter(list, category -> new Select2VO(category.getId(), category.getName()));
        return BaseResponse.success(result);
    }

}
